import 'date_time_extension.dart';

/// FileName string_extension
///
/// @Author lax
/// @Date 2024/3/22
///
/// @Description

extension StringExtension on String {
  /// 转日期
  DateTime? toDateTime() {
    return DateTime.tryParse(this);
  }

  /// 转日期字符串(2020-02-02 00:00:00)
  String? dateTimeString({
    DateType dateType = DateType.kYMDHMS,
    String joinString = '-',
  }) {
    return toDateTime()?.dateTimeString(
      dateType: dateType,
      separator: joinString,
    );
  }

  /// 是否符合正则表达式
  bool regExpFormatter({String? pattern}) {
    if (pattern == null) {
      return true;
    }
    RegExp regExp = RegExp(pattern);
    return regExp.hasMatch(this);
  }
}
